/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.edu.utfpr.dao;

import br.com.caelum.vraptor.ioc.Component;
import br.edu.utfpr.bean.Usuario;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.Query;

/**
 *
 * @author Vanessinha
 */
@Component
public class DaoUsuario {

    private final EntityManager em;

    public DaoUsuario(EntityManager em) {
        this.em = em;
    }

    public void gravar(Usuario u) {
        em.merge(u);
    }

    public List lista() {
        Query q = em.createQuery("select u from Usuario u");
        return q.getResultList();
    }

    public void excluir(Long id) {
        Usuario u = em.find(Usuario.class, id);
        em.remove(u);
    }
}
